<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/style.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
    <div class="box">
        <div id="list">
            <img src="./images/01.png" alt="">
            <img src="./images/02.png" alt="">
            <img src="./images/03.png" alt="">
            <img src="./images/04.png" alt="">
            <img src="./images/05.png" alt="">
        </div>
        <button id="prev"></button>
        <button id="next"></button>
        <div id="btn">
            <span class="select"></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
        
    </div>

    <script>
        $(function(){
            let index=0;

            $("#next").click(function(){
                index++;
                // 实现一个轮回 右箭头
                if(index>4){
                    index=0
                }
                console.log(index);
                show(index);
            })
            $("#prev").click(function(){
                index--;
                // 实现一个轮回 左箭头
                if(index<0){
                    index=$("#list img").length-1;
                }
                console.log(index);
                show(index);
            })

            $("#btn span").click(function(){
                let i =$(this).index();
                console.log(i);
                // 点击焦点后需要重置index的值
                index=i
                show(i);
                
            })
        })

        function show(index){
            $("#list img").eq(index).fadeIn().siblings().fadeOut();
                // 焦点随图片变换
            $("#btn span").eq(index).addClass("select").siblings().removeClass("select");
        }
    </script>
</body>
</html>